package com.demo10;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    //构造函数实例化私有，方法就无法实例化
    private DateUtils(){}

    //日期转为字符串
    public static String dateToString(Date date,String format){
        //实例化SimpleDateFormat的信息
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);

        String string = simpleDateFormat.format(date);

        return string;
    }

    //字符串转为日期
    public static Date stringToDate(String source,String format) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);

        Date date = simpleDateFormat.parse(source);

        return date;
    }
}
